import { defHttp } from '/@/utils/http/axios';
import { isArray } from '/@/utils/is';

const list = (params) => {
  return defHttp.get({ url: '/api-online/online/cgform/head/list', params });
};
const doBatchRemove = (idList) => {
  return doRemove(idList, 0);
};
const doBatchDelete = (idList) => {
  return doRemove(idList, 1);
};
function doRemove(idList, flag) {
  return defHttp.delete(
    {
      url: '/api-online/online/cgform/head/deleteBatch',
      params: {
        ids: idList.join(','),
        flag,
      },
    },
    { joinParamsToUrl: true }
  );
}
const doDatabaseSync = (id, method) => {
  return defHttp.post({
    url: `${'/api-online/online/cgform/api/doDbSynch'}/${id}/${method}`,
    timeout: 12000,
    timeoutErrorMessage: '同步数据库超时，已自动刷新',
  });
};

const doCopyOnlineView = (id) => {
  return defHttp.post({ url: `${'/api-online/online/cgform/head/copyOnline'}?code=${id}` });
};
const doCopyTable = (id, tableName, params) => {
  return defHttp.get({ url: `${'/api-online/online/cgform/head/copyOnlineTable'}/${id}`, params: Object.assign({ tableName }, params) });
};

export { doBatchRemove, doBatchDelete, doDatabaseSync, doCopyOnlineView, doCopyTable, list };
